package com.three.crm.util;

import android.text.TextUtils;
import android.widget.EditText;

import java.util.regex.Pattern;

import static com.three.crm.util.ToastUtils.showToast;


public class PhoneUtils {

    /**
     * 手机号验证
     */
    public static boolean isPhone(final String phone)
    {
        return !TextUtils.isEmpty(phone) && Pattern.matches("^[1][23456789][0-9]{9}$", phone);
    }

    public static boolean onCheckPhone(String phone, EditText editText) {
        if (TextUtils.isEmpty(phone)){
            editText.requestFocus();
            showToast("手机号不能为空!");
            return false;
        }
        if (phone.length() != 11){
            editText.requestFocus();
            showToast("请输入11位手机号!");
            return false;
        }
        if (!isPhone(phone)){
            editText.requestFocus();
            showToast("手机号可能不太正确!");
            return false;
        }
        return true;
    }
}
